<?php

namespace plugin\exportcenter\app\model;

use think\Model;

/**
 * t_export 导出插件-导出记录
 * @property integer $id (主键)
 * @property integer $user_id 导出名称
 * @property string $user_name 导出人
 * @property string $action 方法
 * @property string $name 导出名称
 * @property string $url 下载地址
 * @property string $create_time 创建时间
 * @property string $export_time 导出完成时间
 * @property integer $download_num 下载次数
 * @property string $export_params 导出参数
 * @property string $status 0待导出 1导出中 2导出成功 -1导出失败
 */
class Export extends Model
{
    /**
     * The connection name for the model.
     *
     * @var string|null
     */
    protected $connection = 'mysql';

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 't_export';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $pk = 'id';

    const STATUS_NORMAL = 0;
    const STATUS_EXPORT_ING = 1;
    const STATUS_SUCCESS = 2;
    const STATUS_ERROR = -1;
    const STATUS_CANCEL = -2;
    const STATUS_TEXT_MAP = [
        self::STATUS_NORMAL => "待导出",
        self::STATUS_EXPORT_ING => "导出中",
        self::STATUS_SUCCESS => "导出成功",
        self::STATUS_ERROR => "导出失败",
        self::STATUS_CANCEL => "超时取消",
    ];

    protected $append = [
        'status_text',
    ];

    public function getStatusTextAttr($value, $data)
    {
        return self::STATUS_TEXT_MAP[$data['status']] ?? "";
    }

}
